<template>
    <div class="pageContainer">
        <div class="searchWarp">
            <el-form inline>
                <template v-for="condition in listCondition">
                    <CText :title="condition.name" v-model="condition.value"></CText>
                </template>
            </el-form>
            <div class="schLine">
                <CBtn @click="search(1)">查询</CBtn>
            </div>
        </div>
        <div class="treeTable">
            <div style="flex:1;">
                <div class="btnWarp">
                    <CBtn @click="showEdit">新增</CBtn>
                    <CBtn>批量删除</CBtn>
                </div>
                <CPageTable :data="tableData" :curPage="paging.curPage" :total="paging.total" @changeSize="changeSize" @changePage="search">
                    <template slot-scope="scope">
                        <CBtn type="text" @click="showEdit(scope.row)">修改</CBtn>
                        <CBtn type="text" @click="doDel(scope.row)">删除</CBtn>
                    </template>
                </CPageTable>
            </div>
        </div>

        <CDailog title="新增/编辑" :isShow="isShowEdit" @close="isShowEdit = false" @enter="doSave">
            <el-form :inline="true">
                <CText form v-model="mm.code" title="编码" field="code"></CText>
                <CText form v-model="mm.name" title="名称" field="name"></CText>
                <CSelect form v-model="mm.fkParentId" title="父节点 " field="fkParentId" opType="opServiceType"></CSelect>
                <CText form v-model="mm.val" title="值" field="val"></CText>
            </el-form>
        </CDailog>
    </div>
</template>

<script>
import pagingMixin from '@/mixin/pagingMixin'
export default {
    mixins: [pagingMixin],
    data() {
        return {
            treeData: [],
            model: "sys",
            table: "SysDef"
            
        }
    },
    created() {
        this.templateId = "3";
        
        //取得查询条件
        this.$sys.getPageConditions({id: this.templateId}).then(res => {
            this.listCondition = res.data;
        })
        //查询表格数据
        this.search(1);
    },
    methods: {
        search(page, conditions) {
            if (page) {
                this.paging.curPage = page;
            }
            if (!conditions) {
                conditions = Object.assign([], this.listCondition);
            }
            this.$u.addWhere(conditions, "sys_def.fk_def_type_id", "2")
            this.$sys.templateQuery({
                paging: this.paging,
                listCondition: conditions,
                templateId: this.templateId
            }).then(res => {
                this.tableData = res.data;
                this.paging.total = res.data.paging.total;
            })
        },
        doSave() {
            this.mm.fkDefTypeId = "2";
            this.mm.fkVersionId = "2";
            this.$sys.save(this.model, this.table, this.mm).then(res => {
                if (200 == res.code) {
                    this.isShowEdit = false;
                    this.search(1);
                    this.$message.success("保存成功")
                } else {
                    this.$message.error("保存失败")
                }
            });
        },
    }
}
</script>

<style lang="scss" scoped></style>